# -*- coding: utf-8 -*-
# @Time : 2019/1/10 18:01
# @Author : Administrator
# @File : driver_login.py
# @Project : code
# @title : 执行测试并输出报告
# -*- coding: utf-8 -*-
# @Time : 2019/1/10 16:35
# @Author : Administrator
# @File : boss_login.py
# @Project : code
# @title : woniuboss登录
import requests
import unittest
from bossLogin_test import read_data
from HTMLTestRunner import HTMLTestRunner
from bossLogin_test.login import TestLogin


class DriverLogin(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        t=read_data.ReadData()
        cls.list=t.read_excel()
        cls.test=TestLogin()

    def test001(self):  #正确的用户名、用户密码、验证码，登录成功
        username=self.list[0]["username"]
        password=self.list[0]["password"]
        verifycode=self.list[0]["verifycode"]
        expect=self.list[0]["expect"]
        r=self.test.login_test(username,password,verifycode,expect)
        print(r.text)
        assert r.text == expect

    def test002(self):  #用户名输入不存在的用户名，登录失败
        username = self.list[1]["username"]
        password = self.list[1]["password"]
        verifycode = self.list[1]["verifycode"]
        expect = self.list[1]["expect"]
        r = self.test.login_test(username, password, verifycode, expect)
        print(r.text)
        assert r.text == expect

    def test003(self):  #用户名输入为空，登录失败
        username = self.list[2]["username"]
        password = self.list[2]["password"]
        verifycode = self.list[2]["verifycode"]
        expect = self.list[2]["expect"]
        r = self.test.login_test(username, password, verifycode, expect)
        print(r.text)
        assert  expect in r.text

    def test004(self):  #验证码输入为空，登录失败
        username = self.list[3]["username"]
        password = self.list[3]["password"]
        verifycode = self.list[3]["verifycode"]
        expect = self.list[3]["expect"]
        data_login = {"userName": username, "userPass": password, "checkcode": verifycode}
        r = self.test.login_test(username, password, verifycode, expect)
        print(r.text)
        assert expect in r.text

    def test005(self):   #验证密码输入为空，登录失败
        username = self.list[4]["username"]
        password = self.list[4]["password"]
        verifycode = self.list[4]["verifycode"]
        expect = self.list[4]["expect"]
        r = self.test.login_test(username, password, verifycode, expect)
        print(r.text)
        assert expect in r.text

    def test006(self):   #验证验证码输入错误，登录失败
        username = self.list[5]["username"]
        password = self.list[5]["password"]
        verifycode = self.list[5]["verifycode"]
        expect = self.list[5]["expect"]
        r = self.test.login_test(username, password, verifycode, expect)
        print(r.text)
        assert expect == r.text

    def test007(self):   #验证密码错误，登录失败
        username = self.list[6]["username"]
        password = self.list[6]["password"]
        verifycode = self.list[6]["verifycode"]
        expect = self.list[6]["expect"]
        r = self.test.login_test(username, password, verifycode, expect)
        print(r.text)
        assert expect == r.text



if __name__ == '__main__':
    suite=unittest.TestSuite()
    suite.addTests(unittest.TestLoader().loadTestsFromTestCase(TestLogin))
    with open("login_report.html","w",encoding='utf8') as file:
        runner=HTMLTestRunner(stream=file,verbosity=2)
        runner.run(suite)
    # unittest.main()